using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PharmacyDomain;
using ShivamEMR.Model.DataInterfaces.PharmacyDataInterf;
using ShivamEMR.Model;
//using ShivamEMR.Web.Areas.Pharmacy.Models;

namespace ShivamEMR.Web.Areas.Pharmacy.Controllers
{   
    public class DrugGenericController : Controller
    {
		private readonly IDrugCategoryRepository drugcategoryRepository;
		private readonly IDrugClassRepository drugclassRepository;
		private readonly IDrugGroupRepository druggroupRepository;
		private readonly IDrugGenericRepository druggenericRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DrugGenericController()
        {
            drugcategoryRepository = Registry.RepositoryFactory.GetDrugCategoryRepository();
            drugclassRepository = Registry.RepositoryFactory.GetDrugClassRepository();
            druggroupRepository = Registry.RepositoryFactory.GetDrugGroupRepository();
            druggenericRepository = Registry.RepositoryFactory.GetDrugGenericRepository();
        }

        public DrugGenericController(IDrugCategoryRepository drugcategoryRepository, IDrugClassRepository drugclassRepository, IDrugGroupRepository druggroupRepository, IDrugGenericRepository druggenericRepository)
        {
			this.drugcategoryRepository = drugcategoryRepository;
			this.drugclassRepository = drugclassRepository;
			this.druggroupRepository = druggroupRepository;
			this.druggenericRepository = druggenericRepository;
        }

        //
        // GET: /DrugGeneric/

        public ViewResult Index()
        {
           // return View(druggenericRepository.AllIncluding(druggeneric => druggeneric.DrugClass, druggeneric => druggeneric.Group, druggeneric => druggeneric.Dosage, druggeneric => druggeneric.ContraIndications, druggeneric => druggeneric.Brands, druggeneric => druggeneric.DrugInteractions1, druggeneric => druggeneric.DrugInteractions2));
            return View(druggenericRepository.All);
        }

        //
        // GET: /DrugGeneric/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(druggenericRepository.Find(id));
        }

        //
        // GET: /DrugGeneric/Create

        public ActionResult Create()
        {
			ViewBag.PossibleDrugCategories = drugcategoryRepository.All;
			ViewBag.PossibleDrugClasses = drugclassRepository.All;
			ViewBag.PossibleGroups = druggroupRepository.All;
            return View();
        } 

        //
        // POST: /DrugGeneric/Create

        [HttpPost]
        public ActionResult Create(DrugGeneric druggeneric)
        {
            if (ModelState.IsValid) {
                druggenericRepository.InsertOrUpdate(druggeneric);
                druggenericRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleDrugCategories = drugcategoryRepository.All;
				ViewBag.PossibleDrugClasses = drugclassRepository.All;
				ViewBag.PossibleGroups = druggroupRepository.All;
				return View();
			}
        }
        
        //
        // GET: /DrugGeneric/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleDrugCategories = drugcategoryRepository.All;
			ViewBag.PossibleDrugClasses = drugclassRepository.All;
			ViewBag.PossibleGroups = druggroupRepository.All;
             return View(druggenericRepository.Find(id));
        }

        //
        // POST: /DrugGeneric/Edit/5

        [HttpPost]
        public ActionResult Edit(DrugGeneric druggeneric)
        {
            if (ModelState.IsValid) {
                druggenericRepository.InsertOrUpdate(druggeneric);
                druggenericRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleDrugCategories = drugcategoryRepository.All;
				ViewBag.PossibleDrugClasses = drugclassRepository.All;
				ViewBag.PossibleGroups = druggroupRepository.All;
				return View();
			}
        }

        //
        // GET: /DrugGeneric/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(druggenericRepository.Find(id));
        }

        //
        // POST: /DrugGeneric/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var drugg = druggenericRepository.Find(id);
            druggenericRepository.Delete(drugg);
            druggenericRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

